﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace GSF.Objects
{
    class Enemy:Objects
    {
        int m_HP;
        float m_Speed;
        Queue<Vector2> m_waypoints;

        //sống hay chết
        protected bool m_alive;
        //lượng tiền thưởng
        protected int m_bountyGiven;
        //vector tốc độ
        Vector2 m_velocity;

        float m_spriteTime;

        bool m_stop;
        //điểm trung tâm
        

        public float DistanceToDestination
        {
            get
            {
                return Vector2.Distance(Position, m_waypoints.Peek());
            }
        }


        public bool Stop
        {
            set
            {
                m_stop = value;
            }
            get
            {
                return m_stop;
            }
        }
        public float Speed
        {
            set { m_Speed = value; }
        }
        public Enemy(Game game, string texture, int rows, int cols, Queue<Vector2> waypoints)
            : base(game,texture,rows,cols)
        {
            Random r = new Random();
            m_alive = true;
            m_bountyGiven = 1;
            m_HP = 1;
            m_Speed = r.Next(50, 100) * 0.9f / 100;
            m_velocity = new Vector2();
            m_stop = false;
            m_waypoints = new Queue<Vector2>();

            foreach (Vector2 waypoint in waypoints)
                m_waypoints.Enqueue(waypoint);
            m_Position = m_waypoints.Dequeue();
            m_spriteTime = 0;
        }

      
        public void Update(GameTime gameTime)
        {
            if (!m_stop)
            {
                if (m_waypoints.Count > 0)
                {
                    if (DistanceToDestination < m_Speed*3)
                    {
                        m_Position = m_waypoints.Peek();
                        m_waypoints.Dequeue();
                    }
                    else
                    {

                        m_velocity = Vector2.Multiply(m_Direction, m_Speed);
                        m_Position += m_velocity;

                        m_Direction = m_waypoints.Peek() - m_Position;
                        m_Direction.Normalize();

                    }
                }
                else
                    m_alive = false;
            }
            setRec();

            m_spriteTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (m_spriteTime > 0.5)
            {
                base.update();
                m_spriteTime = 0;
            }
        }

        public void Draw(SpriteBatch sprite)
        {
            base.draw(sprite);
        }
    }
}
